package com.lijing.BubbleSort;

import java.text.SimpleDateFormat;
import java.util.Date;

public class BubbleSort {
    static int[] arr = new int[80000];
    public static void main(String[] args) {
        BubbleSort bs = new BubbleSort();
//        bs.bubbleSort();
//        bs.print();

//        int[] arr = new int[80000];
        for (int i = 0; i < 80000; i++) {
            arr[i] = (int)(Math.random()*80000);
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日hh:mm:ss");
        Date date1 = new Date();
        System.out.println(sdf.format(date1));
        bs.bubbleSort();
        Date date2 = new Date();
        System.out.println(sdf.format(date2));

    }
    //冒泡排序，逐个遍历，两两交换，从大到小排序
    private void bubbleSort(){
        int temp;
        boolean flag = false;
        for (int i = arr.length-1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (arr[j]>arr[j+1]){//如果前一个数小于后一个，则交换
                    flag = true;
                    temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
            if (!flag) {
                break;
            }else {
                flag = false;
            }
        }
    }
    //打印数组
    private void print(){
        for (int j : arr) {
            System.out.print(j);
        }
    }
}
